package exception

import "fmt"

type AppException struct {
	Code string //异常码
	Message string //异常信息
	Cause error //错误原因
}

func (e *AppException) Error() string{
	return fmt.Sprintf("AppException{code '%s', message='%s'}",e.Code,e.Message)
}

func (e *AppException) Unwrap() error{
	return e.Cause
}

func NewAppException(code string) *AppException {
	return &AppException{Code: code}
}

func NewAppExceptionWithCause(code string, cause error) *AppException {
	return &AppException{Code: code, Cause: cause}
}

func NewAppExceptionWithMessage(code, message string) *AppException {
	return &AppException{Code: code, Message: message}
}

func NewAppExceptionFull(code, message string, cause error) *AppException {
	return &AppException{Code: code, Message: message, Cause: cause}
}

